home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interactive Web Graphics with Shout 3D
/
Interactive Web Graphics With Shout 3D.iso
/
pc
/
Shout3Ddemo
/
Shout3d_runtime
/
codebase
/
applets
/
ExamineWithButtonsApplet.java
< prev
next >
Wrap
Text File
|
2000-11-03
|
4KB
|
131 lines
/**
Company: Eyematic Interfaces
Project: Shout3D 2.0 Sample Code
Class: ExaminePanel with buttons to control it.
Date: Nov 1, 2000
Description: Class for ExaminePanel
(C) Copyright Eyematic Interfaces, Inc. - 1997-2000 - All rights reserved
*/
package applets;
import java.awt.*;
import shout3d.*;
/**
* A simple panel class that shows how to lay out buttons with a Shout3DPanel.
* Puts up buttons to control the behavior of an ExaminePanel.
*/
public class ExamineWithButtonsApplet extends Shout3DApplet {
// Buttons to select drag style:
Label dragStyleLabel;
Checkbox bySpeedCheckbox;
Checkbox byOffsetCheckbox;
// Buttons to change the center of rotation
Label centerSelectLabel;
Button upButton;
Button downButton;
Button leftButton;
Button rightButton;
int BUTTON_HEIGHT = 25;
// Reference to the panel.
ExaminePanel myExaminePanel;
/**
* Very important:
* Add buttons during initShout3DPanel, not during init().
*/
public void initShout3DPanel(){
int width = size().width;
int height = size().height;
int panelHeight = height - 2 * BUTTON_HEIGHT;
int panelWidth = width;
int buttonWidth = width/5;
panel = new ExaminePanel(this, panelWidth, panelHeight);
myExaminePanel = (ExaminePanel) panel;
dragStyleLabel = new Label("Drag Style:");
bySpeedCheckbox = new Checkbox("By Speed", true);
byOffsetCheckbox = new Checkbox("By Offset", false);
dragStyleLabel.reshape(0, panelHeight, buttonWidth, BUTTON_HEIGHT);
bySpeedCheckbox.reshape( buttonWidth, panelHeight, buttonWidth, BUTTON_HEIGHT);
byOffsetCheckbox.reshape(2*buttonWidth, panelHeight, buttonWidth, BUTTON_HEIGHT);
add(dragStyleLabel);
add(bySpeedCheckbox);
add(byOffsetCheckbox);
centerSelectLabel = new Label("Move Center:");
upButton = new Button("Up");
downButton = new Button("Down");
leftButton = new Button("Left");
rightButton = new Button("Right");
centerSelectLabel.reshape(0, panelHeight+BUTTON_HEIGHT, buttonWidth, BUTTON_HEIGHT);
upButton.reshape( buttonWidth, panelHeight+BUTTON_HEIGHT, buttonWidth, BUTTON_HEIGHT);
downButton.reshape( 2*buttonWidth, panelHeight+BUTTON_HEIGHT, buttonWidth, BUTTON_HEIGHT);
leftButton.reshape( 3*buttonWidth, panelHeight+BUTTON_HEIGHT, buttonWidth, BUTTON_HEIGHT);
rightButton.reshape( 4*buttonWidth, panelHeight+BUTTON_HEIGHT, buttonWidth, BUTTON_HEIGHT);
add(centerSelectLabel);
add(upButton);
add(downButton);
add(leftButton);
add(rightButton);
}
public boolean action(Event e, Object o) {
if (e.target instanceof Checkbox) {
// Select a dragStyle.
Checkbox c = (Checkbox) e.target;
boolean isBySpeed = true;
if (c == bySpeedCheckbox){
isBySpeed = bySpeedCheckbox.getState();
byOffsetCheckbox.setState(!isBySpeed);
}
else if (c == byOffsetCheckbox){
isBySpeed = !byOffsetCheckbox.getState();
bySpeedCheckbox.setState(isBySpeed);
}
myExaminePanel.currentDragStyle = (isBySpeed) ? ExaminePanel.BY_SPEED :
ExaminePanel.BY_OFFSET;
}
if (e.target instanceof Button) {
if (e.target == upButton) {
myExaminePanel.rotationCenter = myExaminePanel.bboxCenter;
myExaminePanel.rotationCenter[1] = myExaminePanel.rotationCenter[1]+1;
myExaminePanel.resetCamera();
return true;
}
if (e.target == leftButton) {
myExaminePanel.rotationCenter = myExaminePanel.bboxCenter;
myExaminePanel.rotationCenter[0] = myExaminePanel.rotationCenter[0]-1;
myExaminePanel.resetCamera();
return true;
}
if (e.target == rightButton) {
myExaminePanel.rotationCenter = myExaminePanel.bboxCenter;
myExaminePanel.rotationCenter[0] = myExaminePanel.rotationCenter[0]+1;
myExaminePanel.resetCamera();
return true;
}
if (e.target == downButton) {
myExaminePanel.rotationCenter = myExaminePanel.bboxCenter;
myExaminePanel.rotationCenter[1] = myExaminePanel.rotationCenter[1]-1;
myExaminePanel.resetCamera();
return true;
}
return false;
}
//not a button event
return false;
}//end of action method
}